/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var itemsOperationsNames = "";
function getVerticalTabs2Data() {
    var returnData = "";
    for (i = 0; i < vtasbDivs2.length; i++) {

        var mayaData = getValueData(vtasbDivs2[i] + ".tarns_getinputData", 1);


        var ival = $(".tarns_eventinputs." + vtasbDivs2[i]).val();
        ival = ival.replaceAll(" ", "_");
        var icom = vtasbDivs2[i];

        $("." + vtasbDivs2[i] + ".tarns_getinputData").remove();

        if ($.trim($(".tarns_eventinputs." + vtasbDivs2[i]).val()) != "") {
            var tvalue = "getselectData__event__display-name;" + vtasbDivs2[i] + "__" + $(".tarns_eventinputs." + vtasbDivs2[i]).val() + "__" + $(".tarns_Display_Names." + vtasbDivs2[i]).val();
            returnData += "\n" + returnInputField("__tarnsData  " + vtasbDivs2[i] + "  tarns_getinputData", tvalue);

            itemsOperationsNames += "__" + vtasbDivs2[i];
        }

        var merEventdata = 0;
        var oldf = "";
        if (mayaData[0] != null) {

            var oldf = mayaData[0].replaceAll(" ", "_");

            $(".trns_more." + oldf + "." + icom).remove();


            $(".trns_pattern." + oldf + "." + icom).remove();

        }



        $(".more_event." + vtasbDivs2[i]).each(function() {
            merEventdata++;
            if ($(this).val() != "") {


                var value = "value__display-name;" + $(".more_event." + vtasbDivs2[i]).eq(merEventdata - 1).val() + "__" + $(".more_DisplayName." + vtasbDivs2[i]).eq(merEventdata - 1).val();
                returnData += "\n" + returnInputField("  trns_more  " + ival + "   " + icom + "  " + merEventdata, value);

            }

        })


        if ($.trim($(".trns_pattern_eventinput." + vtasbDivs2[i]).val()) != "") {


            tvalue = "event__display-name;" + $(".trns_pattern_eventinput." + vtasbDivs2[i]).val() + "__" + $(".trns_pattern_Display_Name." + vtasbDivs2[i]).val();
            returnData += "\n" + returnInputField("__tarnsData  " + ival + "   " + icom + " trns_pattern", tvalue);
        }
    }





    return returnData;


}


function getVerticalTabs1Data() {
    var returnData = "";

    for (i = 0; i < vtasbDivs1.length; i++) {
        $("." + vtasbDivs1[i] + ".tarns_getinputData").remove();
        var thist = $(".tarns_eventinput." + vtasbDivs1[i]).val();

        if ($.trim(thist) != "") {

            itemsOperationsNames += "__" + vtasbDivs1[i];
            var tvalue = "getselectData__event__display-name;" + vtasbDivs1[i] + "__" + $(".tarns_eventinput." + vtasbDivs1[i]).val() + "__" + $(".tarns_Display_Name." + vtasbDivs1[i]).val();
            returnData += "\n" + returnInputField("__tarnsData  " + vtasbDivs1[i] + "  tarns_getinputData", tvalue);
        }
    }

    return returnData

}


function VTabsAction(id) {

    var myClass = id.replace(" ", "");
    $(".alldvs").hide("slow");
    $("." + myClass).show("slow");
    $(".tabsv").removeClass("selected");
    $("#" + id).addClass("selected");

}



var vtasbDivs2 = ["migrate-error-resolve", "synchronise-error-resolve"];
var vtasbDivs1 = ["migrate", "synchronise-create", "synchronise-update", "user-event", "external-event", "deferred-response"]


function itemop_dataForRow(thisTabe2, th) {

    var moreData = "";

    if (th != null && th != "xx") {

        var myvals = []

        myvals = getValueDataByValue(th.val(), 1);




        moreData = '<tr class="' + thisTabe2 + ' addprow  new morerow " style="display: table-row;">\n\
 <td style="font-size: 10pt;">Value:</td>\n\
<td style="font-size: 10pt;">\n\
<input class="more_event  ' + thisTabe2 + '" style="width:100px;"  value="' + myvals[0] + '" >\n\
</td><td style="font-size: 10pt;">Display Name:</td><td style="font-size: 10pt;">\n\
<input class="more_DisplayName ' + thisTabe2 + '" value="' + myvals[1] + '" style="width:100px;"></td></tr>';

    } else {

        moreData = '<tr class="' + thisTabe2 + ' addprow  new morerow " style="display: table-row;">\n\
 <td style="font-size: 10pt;">Value:</td><td style="font-size: 10pt;">\n\
<input class="more_event  ' + thisTabe2 + '" style="width:100px;" >\n\
</td><td style="font-size: 10pt;">Display Name:</td><td style="font-size: 10pt;">\n\
<input class="more_DisplayName ' + thisTabe2 + '" style="width:100px;"></td></tr>';


    }








    return moreData;
}

function itemop_doOnLoad() {

    for (var myi = 0; myi < vtasbDivs2.length; myi++) {

        var tab = vtasbDivs2[myi];

        // alert (".trns_more."+tab +"::"+$(".trns_more."+tab).size());
        $("." + tab + " .addprow").hide();
        $(".trns_more." + tab).each(function() {

            $("." + tab + " .addh.addprow:last").after(itemop_dataForRow(tab, $(this)));

        });


        if ($(".trns_more." + tab).size() > 0) {



            $("." + tab + ".chadd").attr("checked", "checked");


            $("." + tab + " .addprow").show();



        } else {

            $("." + tab + " .addprow").hide();

        }


    }









}

function createVerticalTabs2() {
    var alldivs = document.createElement('div');

    for (var myi = 0; myi < vtasbDivs2.length; myi++) {

        var thisTabe = vtasbDivs2[myi];
        //getselectData__event__display-name;
        var mayaData = getValueData(thisTabe + ".tarns_getinputData", 1);


        var mayaDatapattern = getValueData(thisTabe + ".trns_pattern", 1);





        var divd2 = document.createElement('div');

        divd2.setAttribute('class', 'alldvs divt2   ' + thisTabe);

        divd2.setAttribute('style', 'display:none;');

        var table = document.createElement('table');


        table.setAttribute('class', 'merTable');

        table.style.width = '100%';
        table.style.height = '100%';
        var tbody = document.createElement('tbody');


        row = document.createElement('tr');
        td = document.createElement('td');
        td.style.fontSize = '10pt';
        mxUtils.write(td, 'Event:');
        row.appendChild(td);




        var td = createIntput(mayaData[1], 'tarns_eventinputs ' + thisTabe, 'width:100px');
        row.appendChild(td);



        td = document.createElement('td');
        td.style.fontSize = '10pt';
        mxUtils.write(td, 'Display Name:');
        row.appendChild(td);



        td = createIntput(mayaData[2], 'tarns_Display_Names ' + thisTabe, 'width:100px');
        row.appendChild(td);



        row.appendChild(td);
        tbody.appendChild(row);

        row = document.createElement('tr');
        td = document.createElement('td');
        td.style.fontSize = '10pt';

        myinput = document.createElement('input');


        myinput.setAttribute("type", "checkbox");
        myinput.setAttribute("class", "ch_" + thisTabe);



        myinput.onchange = function() {


            var tbClass = "merTable";

            if ($(this).is(':checked')) {




                var mid = $(this).attr("id");

                mid = mid.replace("__mch", "");


                $("." + mid + " ." + tbClass + " .addprow").show();
            } else {


                var mid = $(this).attr("id");

                mid = mid.replace("__mch", "");
                $("." + mid + " ." + tbClass + " .addprow").hide();

            }

        }




        myinput.setAttribute('class', thisTabe + " chadd");
        myinput.setAttribute('id', thisTabe + "__mch");
        td.appendChild(myinput);
        row.appendChild(td);
        td = document.createElement('td');
        td.style.fontSize = '10pt';
        td.setAttribute('colspan', '3');
        mxUtils.write(td, 'Add Parameters');
        row.appendChild(td);
        tbody.appendChild(row);


        row = document.createElement('tr');
        row.setAttribute('class', 'addh addprow');
        row.setAttribute('style', 'display:none');


        td = document.createElement('td');
        td.style.fontSize = '10pt';
        td.setAttribute('colspan', '3');
        td.setAttribute('class', 'subtitle');
        mxUtils.write(td, 'EventData');
        row.appendChild(td);
        tbody.appendChild(row);


        row = document.createElement('tr');



        row.setAttribute('class', 'addprow');
        row.setAttribute('style', 'display:none');
        td = document.createElement('td');
        td.style.fontSize = '10pt';
        var addRow = document.createElement('input');
        addRow.setAttribute('class', 'addmore');
        addRow.setAttribute('value', '+');
        addRow.setAttribute('type', 'button');

        addRow.setAttribute('id', thisTabe + '___trns');



        addRow.onclick = function() {

            var thisTabe2 = this.id.split("___")[0];


            $(this).parent().parent("tr").after(itemop_dataForRow(thisTabe2, "xx"));


        }

        td.appendChild(addRow);

        row.appendChild(td);
        tbody.appendChild(row);
        row = document.createElement('tr');
        row.setAttribute('class', 'addprow');
        row.setAttribute('style', 'display:none');
        td = document.createElement('td');
        td.style.fontSize = '10pt';


        td.setAttribute('colspan', '3');

        td.setAttribute('class', 'subtitle');

        mxUtils.write(td, 'Event - Data pattern');



        row.appendChild(td);
        tbody.appendChild(row);


        row = document.createElement('tr');

        row.setAttribute('class', 'addprow');
        row.setAttribute('style', 'display:none');
        td = document.createElement('td');
        td.style.fontSize = '10pt';
        mxUtils.write(td, 'Value:');
        row.appendChild(td);




        td = createIntput(mayaDatapattern[0], 'trns_pattern_eventinput ' + thisTabe, 'width:100px');
        row.appendChild(td);




        td = document.createElement('td');
        td.style.fontSize = '10pt';
        mxUtils.write(td, 'Display Name:');
        row.appendChild(td);



        td = createIntput(mayaDatapattern[1], 'trns_pattern_Display_Name ' + thisTabe, 'width:100px');
        row.appendChild(td);


        tbody.appendChild(row);

        table.appendChild(tbody);
        divd2.appendChild(table);
        alldivs.appendChild(divd2);





    }

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "file.js";
    script.onload = function() {

        itemop_doOnLoad();


    };
    alldivs.appendChild(script);


    return alldivs;
}

function  createVerticalTabs() {

    var alldivs = document.createElement('div');
    for (i = 0; i < vtasbDivs1.length; i++) {

        var thisparent = vtasbDivs1[i];
        var mayaData = getValueData(thisparent + ".tarns_getinputData", 1);


        var divd1 = document.createElement('div');

        divd1.setAttribute('class', ' alldvs ' + thisparent);

        if (i > 0) {


            divd1.setAttribute('style', ' display:none ');

        }



        var table = document.createElement('table');
        table.style.width = '100%';
        table.style.height = '100%';
        var tbody = document.createElement('tbody');

        row = document.createElement('tr');




        td = document.createElement('td');
        td.style.fontSize = '10pt';
        mxUtils.write(td, 'Event:');
        row.appendChild(td);




        var td = createIntput(mayaData[1], 'tarns_eventinput ' + thisparent, 'width:100px');
        row.appendChild(td);




        td = document.createElement('td');
        td.style.fontSize = '10pt';
        mxUtils.write(td, 'Display Name:');
        row.appendChild(td);



        td = createIntput(mayaData[2], 'tarns_Display_Name ' + thisparent, 'width:100px');
        row.appendChild(td);
        row.appendChild(td);

        tbody.appendChild(row);
        table.appendChild(tbody);
        divd1.appendChild(table);

        alldivs.appendChild(divd1);


    }

    return alldivs;

}

function getTransValueXml() {

    var retunData = "";
    var retundataSub = "";


    retunData += "<item-operations>";

    $(".tarns_getinputData").each(function() {

        var mydata = $(this).val();
        var myval = getValueDataByValue(mydata, 1);
        var vold = myval[1].replaceAll(" ", "_");

        if (myval[1] != "" && myval[1] != null) {

            retundataSub += "<" + myval[0] + "  " + getAttrValue(mydata, "getselectData") + ">";


            $(".trns_more" + "." + myval[0] + "." + vold).each(function() {

                var mydatamore = $(this).val();

                retundataSub += "<eventdata  " + getAttrValue(mydatamore) + " />";


            })




            var data = $(".trns_pattern" + "." + myval[0] + "." + vold).val();


            if ($.trim(getAttrValue(data)) != "") {

                retundataSub += "<eventdata-pattern  " + getAttrValue(data) + " />";
            }





            retundataSub += "</" + myval[0] + ">";
        }



    })


    retunData += retundataSub;

    retunData += "</item-operations>";

    if ($.trim(retundataSub) == "")
    {
        retunData = "";

    }
    return retunData;

}

function getDirectionXml() {

    var value = getTransValueXml();
    setSesstion("itemOperation", value, function() {
    });
    return value;
}

function ItemsOperationsDialog(editorUi, valu, targetValue)
{
    var eventSataus = "1";

    var div = document.createElement('div');

    div.appendChild(createItem("Items Operations", "", "thtitle"));

    /////////////////////////////////////////////////////////////////////
    var divd1 = document.createElement('div');

    divd1.setAttribute('class', 'tabsvAll');
    /////////////////////////////////////////////////////////////////////


    mi = mxUtils.button("Migrate", function()
    {
        VTabsAction('migrate');

    });
    mi.setAttribute('id', 'migrate');
    mi.setAttribute('class', 'tabsv mi selected');

    divd1.appendChild(mi);


    mi = mxUtils.button("Migrate Error Resolve", function()
    {
        VTabsAction('migrate-error-resolve');
    });

    divd1.appendChild(mi);

    mi.setAttribute('id', 'migrate-error-resolve');
    mi.setAttribute('class', 'tabsv mi ');

    mi = mxUtils.button("Sync Create", function()
    {
        VTabsAction('synchronise-create');
    });
    mi.setAttribute('id', 'synchronise-create');
    mi.setAttribute('class', 'tabsv mi ');

    divd1.appendChild(mi);

    mi = mxUtils.button("Sync Update", function()
    {
        VTabsAction('synchronise-update');
    });

    mi.setAttribute('id', 'synchronise-update');
    mi.setAttribute('class', 'tabsv mi ');
    divd1.appendChild(mi);


    mi = mxUtils.button("Sync Error resolve", function()
    {
        VTabsAction('synchronise-error-resolve');
    });
    mi.setAttribute('id', 'synchronise-error-resolve');
    mi.setAttribute('class', 'tabsv mi ');
    divd1.appendChild(mi);


    mi = mxUtils.button("External Event", function()
    {
        VTabsAction('external-event');
    });
    mi.setAttribute('id', 'external-event');
    mi.setAttribute('class', 'tabsv mi ');
    divd1.appendChild(mi);

    mi = mxUtils.button("Deferred Response", function()
    {
        VTabsAction('deferred-response');
    });
    mi.setAttribute('id', 'deferred-response');
    mi.setAttribute('class', 'tabsv mi ');
    divd1.appendChild(mi);

    div.appendChild(divd1);


    /////////////////////////////////////////////////////////////////////
    var divd1 = document.createElement('div');

    divd1.setAttribute('class', 'alldvs EnterEvent');
    divd1.setAttribute('style', 'Display:none');

    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');

    row = document.createElement('tr');

    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Event:');
    row.appendChild(td);

    td = document.createElement('td');
    td.style.fontSize = '10pt';
    var myinput = document.createElement('input');
    myinput.setAttribute('class', 'EnterEvent_event');
    myinput.setAttribute('style', 'width:100px;');
    td.appendChild(myinput);
    row.appendChild(td);


    tbody.appendChild(row);
    table.appendChild(tbody);
    divd1.appendChild(table);

    div.appendChild(divd1);





    /////////////////////////////////////////////////////////////////////
    var divd1 = document.createElement('div');

    divd1.setAttribute('class', 'DontEvent');
    divd1.setAttribute('style', 'Display:none');

    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');

    row = document.createElement('tr');

    tbody.appendChild(row);
    table.appendChild(tbody);
    divd1.appendChild(table);





    div.appendChild(divd1);

    div.appendChild(createVerticalTabs());

    div.appendChild(createVerticalTabs2());


    var v = valu.replaceAll(" ", "_");

    var tvalue = "";







    var myup = mxUtils.button("Update", function() {
        var myadddata = "";

        itemsOperationsNames = "";



        myadddata += getVerticalTabs1Data();
        myadddata += getVerticalTabs2Data();




        setSesstion("itemsOperations_Names", itemsOperationsNames);

        $(".itmedata").append(myadddata);
        getDirectionXml();

        alert("Item Operations has been updated.");


        //  editorUi.hideDialog();

    });

    myup.setAttribute('class', 'myupdate');
    div.appendChild(myup);


    this.container = div;
}



